package zdream.pmfield.data.foe;

public enum Type {
	NORMAL,
	GRASS,
	FIRE,
	WATER,
	WIND, // flying
	SAND, // ground
	STEEL,
	MIND, // ghost
	ELECTRIC,
	ICE,
	DARK,
	LIGHT, // fairy
	OTHER;

	public static final String TYPE = "type";

	public static class TypeWithWeight {
		public final Type type;
		public final byte weight; // 0~24
		public static final byte WEIGHT_FULL = 24;
		public static final byte WEIGHT_LOW = 7;
		public static final byte WEIGHT_HIGH = WEIGHT_FULL - WEIGHT_LOW;
		public static final byte WEIGHT_HALF = WEIGHT_FULL / 2;

		public TypeWithWeight(Type type, byte weight) {
			this.type = type;
			this.weight = weight;
		}

		public TypeWithWeight(Type type) {
			this(type, WEIGHT_FULL);
		}
	}

	public final TypeWithWeight withFullWeight = new TypeWithWeight(this);

	public static final byte TYPE_FIXED_RATE_LEVEL_IMMUNE = -3;
	public static final byte[][] TYPE_FIXED_TABLE = {
		{ 0, 0, 0, 0, 0, 0,-1,-1, 0, 0, 0, 0},
		{ 0,-1,-1, 1,-1, 1,-1, 0, 0, 0, 0, 1},
		{ 0, 1,-1,-1, 0,-1, 1, 0, 0, 1, 0, 0},
		{ 0,-1, 1,-1, 0, 1, 0, 0, 0, 0, 0, 0},
		{ 0, 1, 0, 0, 0, 0,-1, 0,-1, 0, 1, 0},
		{ 0,-1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0},
		{ 0, 0,-1,-1, 0, 0,-1, 0,-1, 1, 0, 1},
		{-1, 0, 0, 0, 0, 0, 0, 1, 0, 0,-3, 0},
		{ 0,-1, 0, 1, 1,-3, 0, 0,-1, 0, 0, 0},
		{ 0, 1,-1,-1, 1, 1,-1, 0, 0,-1, 0, 0},
		{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,-1,-1},
		{ 0, 0, 0, 0, 0, 0,-1, 0, 0, 0, 1, 1},
	};

	public byte fixRate(Type to) {
		if (this == OTHER || to == OTHER) {
			return 0;
		}
		return TYPE_FIXED_TABLE[this.ordinal()][to.ordinal()];
	}
}
